import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";
import Layout from "@/views/Layout/index.vue";
import Login from "@/views/Login/index.vue";
import Home from "@/views/Home/index.vue";
import UserManange from "@/views/UserManange/index.vue";
import Goods from "@/views/Goods/index.vue";
import Self from "@/views/Self/index.vue";
import ChangePassword from "@/views/Self/ChangePassword/index.vue";
import GoodsList from "@/views/Goods/GoodsList/index.vue";
import OrderManage from "@/views/Goods/OrderManage/index.vue";

const routes: Array<RouteRecordRaw> = [
  // 首次访问重定向到登陆页面
  // {
  //   path: "/",
  //   redirect: "/login",
  // },
  {
    path: "/",
    component: Layout,
    children: [
      {
        path: "/",
        component: Home,
        meta: { title: "首页" },
      },
      {
        path: "/usermanage",
        name: "UserManange",
        component: UserManange,
        meta: { title: "用户管理" },
        children: [],
      },
      {
        path: "/goodsmanage",
        name: "Goods",
        component: Goods,
        meta: { title: "商品管理" },
        children: [
          {
            path: "/goodsmanage/goodslist",
            name: "GoodsList",
            component: GoodsList,
            meta: { title: "商品列表" },
          },
          {
            path: "/goodsmanage/ordermanage",
            name: "OrderManage",
            component: OrderManage,
            meta: { title: "订单管理" },
          },
        ],
      },
      {
        path: "/self",
        name: "self",
        component: Self,
        meta: { title: "个人中心" },
        children: [
          {
            path: "/self/changepassword",
            name: "changepassword",
            component: ChangePassword,
            meta: { title: "修改密码" },
          },
        ],
      },
    ],
  },

  {
    path: "/login",
    name: "login",
    component: Login,
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});
export default router;
